import asyncio, pyautogui, random

from core.base_actions import BaseActions
from core.utils import get_image_pos

class AutoOrderActions(BaseActions):
  async def start_dz_order(self):
    await self.log("Starting DZ Order")
    await self.log("开始锻造订单")
    complete_pos = get_image_pos("images_2/word_dz_order_success.png", confidence = 0.8)
    order_conut = 0
    while complete_pos is None:
      pyautogui.press("t")
      if order_conut == 0:
        await asyncio.sleep(random.uniform(4, 5))
      if order_conut > 0 and order_conut % 3 == 0:
        await asyncio.sleep(random.uniform(1, 2))
      if order_conut % 3 == 1:
        await asyncio.sleep(random.uniform(1, 2))
      if order_conut % 3 == 2:
        await asyncio.sleep(random.uniform(4, 5))
      complete_pos = get_image_pos("images_2/word_dz_order_success.png", confidence = 0.8)
      await self.log(f"锻造订单 {order_conut}")
      order_conut += 1
    await self.log("锻造订单完成")

  async def start_fm_order(self):
    await self.log("Starting FM Order")
    await self.log("开始附魔订单")
    complete_pos = get_image_pos("images_2/word_fm_order_success.png", confidence = 0.8)
    order_conut = 0
    while complete_pos is None:
      pyautogui.press("e" if random.random() > 0.5 else "f8")
      if order_conut == 0:
        await asyncio.sleep(random.uniform(4, 5))
      if order_conut > 0 and order_conut % 3 == 0:
        await asyncio.sleep(random.uniform(1, 2))
      if order_conut % 3 == 1:
        await asyncio.sleep(random.uniform(1, 2))
      if order_conut % 3 == 2:
        await asyncio.sleep(random.uniform(4, 5))
      complete_pos = get_image_pos("images_2/word_fm_order_success.png", confidence = 0.8)
      await self.log(f"附魔订单 {order_conut}")
      order_conut += 1
    await self.log("附魔订单完成")